home *** CD-ROM | disk | FTP | other *** search
- /* SelectFolder.c: Utility Standard File folder selection routines for ProjectDrag.
- * Copied from Inside Macintosh: Files. Not yet used in ProjectDrag.
- *
- * A set of applets for drag and drop source control by Tim Maroney.
- * See develop, issue 23 for details.
- *
- * Built on DropShell by Leonard Rosenthol, Stephan Somogyi, and Marshall Clow,
- * and using the MoreFiles utilities by Jim Luther.
- *
- * This software is free, but don't modify and redistribute it without
- * changing the status window to indicate your name and your changes!
- */
-
- #include <Types.h>
- #include <StandardFile.h>
- #include <QuickDraw.h>
- #include <TextUtils.h>
-
-
- Str255 gPrevSelectedName;
- Boolean gDirSelectionFlag;
-
-
- pascal Boolean MyCustomFileFilter(CInfoPBPtr pb, Ptr myDataPtr)
- {
- #pragma unused (myDataPtr)
- return (pb->hFileInfo.ioFlAttrib & 0x10) == 0;
- }
-
- void SetButtonTitle(ControlHandle button, StringPtr name, Rect *buttonRect)
- {
- short result, width;
- Str255 title;
-
- BlockMoveData(name, gPrevSelectedName, name[0] + 1);
- width = (buttonRect->left - buttonRect->right)
- - (StringWidth("Select \"\"") + CharWidth(' '));
- result = TruncString(width, name, smTruncMiddle);
- title[0] = 0;
- AppendString(title, "Select \"");
- AppendString(title, name);
- AppendString(title, "\"");
- SetCTitle(button, title);
- ValidRect(buttonRect);
- }
-
- #define kGetDirBTN 10
-
- pascal short MyDlgHook(short item, DialogPtr theDialog, Ptr myDataPtr)
- {
- short myType;
- Handle myHandle;
- Rect myRect;
- Str255 myName;
- CInfoPBRec myPB;
- StandardFileReply *mySFRPtr;
- OSErr myErr;
- short myReturnValue = item;
-
- if (GetWRefCon(theDialog) != sfMainDialogRefCon)
- return myReturnValue;
-
- GetDItem(theDialog, kGetDirBTN, &myType, &myHandle, &myRect);
- if (item == sfHookFirstCall)
- {
- myPB.hFileInfo.ioNamePtr = myName;
- myPB.hFileInfo.ioVRefNum = -LMGetSFSaveDisk();
- myPB.hFileInfo.ioFDirIndex = -1;
- myPB.hFileInfo.ioDirID = LMGetCurDirStore();
- err = PBGetCatInfoSync(&myPB);
- SetButtonTitle((ControlHandle)myHandle, myName, &myRect);
- }
- else
- {
- mySFRPtr = (StandardFileReply*)myDataPtr;
- if (mySFRPtr->sfIsFolder || mySFRPtr->sfIsVolume)
- {
- BlockMoveData(mySFRPtr->sfFile.name, myName, mySFRPtr->sfFile.name[0] + 1);
- }
- else
- {
- myPB.hFileInfo.ioNamePtr = myName;
- myPB.hFileInfo.ioVRefNum = mySFRPtr->sfFile.vRefNum;
- myPB.hFileInfo.ioFDirIndex = -1;
- myPB.hFileInfo.ioDrDirID = mySFRPtr->sfFile.parID;
- myErr = PBGetCatInfoSync(&myPB);
- if (!EqualString(myName, gPrevSelectedName, true, true))
- SetButtonTitle((ControlHandle)myHandle, myName, &myRect);
- switch (item)
- {
- case kGetDirBTN:
- myReturnValue = sfItemCancelButton;
- break;
- case sfItemCancelButton:
- gDirSelectionFlag = false;
- }
- }
- }
-
- return myReturnValue;
- }
-
- #define rGetDirectoryDLOG 128
-
- StandardFileReply DoGetDirectory(void)
- {
- StandardFileReply myReply;
- Point myPoint;
-
- gPrevSelectedName[0] = 0;
- gDirSelectionFlag = true;
- myPoint.h = myPoint.v = -1;
-
- CustomGetFile(myCustomFileFilter, -1, NULL, &myReply, rGetDirectoryDLOG,
- &myPoint, myDlgHook, NULL, NULL, NULL, &myReply);
-
- if (gDirSelectionFlag)
- {
- myReply.sfFile.name[0] = 0;
- if (myReply.sfIsVolume)
- {
- Str255 myName;
- myName[0] = 0;
- AppendString(myName, myReply.sfFile.name);
- AppendString(myName, "\p:");
- AppendString(myReply.sfFile.name, myName);
- }
- else if (gDirSelectionFlag)
- {
- AppendString(myReply.sfFile.name, gPrevSelectedName);
- }
- }
- myReply.sfValid = gDirSelectionFlag;
- return myReply;
- }
-